import { http } from "@/utils/http";

// 获取所有支付订单列表
export const getAllPayments = (params: {
  userId?: number | string;
  page: number;
  size: number;
  status?: string;
  startDate?: string;
  endDate?: string;
}) => {
  return http.request<any>("get", `/api/admin/payment/orders`, {
    params
  });
};
// 查询订单详情/api/admin/finance/payments/{orderNo}
export const getPaymentDetail = (orderNo: string) => {
  return http.request<any>("get", `/api/admin/finance/payments/${orderNo}`);
};
// 获取充值统计
export const getPaymentStats = (params: {
  startDate?: string;
  endDate?: string;
}) => {
  return http.request<any>("get", `/api/admin/finance/payments/stats`, {
    params
  });
};
// 获取退款申请列表
export const getRefundRequests = (params: { page: number; size: number }) => {
  return http.request<any>(
    "get",
    "/api/admin/finance/payments/refund-requests",
    {
      params
    }
  );
};
// 手动更新订单状态
export const updatePaymentStatus = (
  orderNo: string,
  params: {
    status?: string;
    remark?: string;
  }
) => {
  return http.request<any>(
    "post",
    `/api/admin/finance/payments/${orderNo}/status`,
    {
      params
    }
  );
};
// 退款
export const refundPayment = (
  orderNo: string,
  params: {
    txHash?: string;
    reason?: string;
  }
) => {
  return http.request<any>(
    "post",
    `/api/admin/finance/payments/${orderNo}/refund`,
    {
      params
    }
  );
};
// 无效化订单/api/admin/finance/payments/{orderNo}/invalidate
export const invalidatePayment = (
  orderNo: string,
  params: {
    reason: string;
  }
) => {
  return http.request<any>(
    "post",
    `/api/admin/finance/payments/${orderNo}/invalidate`,
    {
      params
    }
  );
};
// 标记过期订单
export const markExpired = () => {
  return http.request<any>("post", "/api/admin/finance/payments/mark-expired");
};

// 手动确认
export const manualConfirm = (
  orderNo: string,
  params: {
    txHash?: string;
    reason?: string;
  }
) => {
  return http.request<any>(
    "post",
    `/api/admin/payment/order/${orderNo}/manual-confirm`,
    {
      params
    }
  );
};
